import {useEffect, useState} from 'react'


function Son() {
    useEffect(() => {
        let timer = setInterval(() => {
            console.log('timer is working...')
        }, 1000);

        // 返回的函数通常用来 清除 副作用函数，组件卸载时自动执行
        return () => clearInterval(timer)
    }, []);
    return <div>this is son</div>
}


function App() {
    let [show, setShow] = useState(true);
    return <div>
        {show && <Son/>}
        <button onClick={() => setShow(false)}>unload son</button>
    </div>

}

export default App;